package com.third.utils;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import java.util.concurrent.TimeUnit;

/**
 * @author 唐博文
 * @version 2023.1.2
 * @date 2023/10/22 20:26 星期日
 */

//限流工具
@Component
public class FlowUtils {
    @Resource
    StringRedisTemplate stringRedisTemplate;
    
    //发送验证码的冷却时间
    public boolean limitOnceCheck(String key,int blockTime){
        if(Boolean.TRUE.equals(stringRedisTemplate.hasKey(key))){
            return false;
        }else{
            stringRedisTemplate.opsForValue().set(key, "", blockTime, TimeUnit.SECONDS);
            return true;
        }
    }
}
